﻿package birdry.display
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Stage;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.BlurFilter;
	import gs.TweenLite;
	
	
	/**
	 * ...
	 * @author 
	 */
	public class Dimmed	extends Sprite		{
		
		var box:Sprite;
		
		var dcWidth:uint;
		var dcHeight:uint;
		
		public var _color:uint = 0x000000;
		public var _alpha:Number = 0.5;
		public var _speed:Number = 0;
		
		public function Dimmed(dcWidth:uint, dcHeight:uint, alpha:Number = 0.5, color:uint = 0x000000): void	{
			this.dcWidth = dcWidth;
			this.dcHeight = dcHeight;
			this._alpha = alpha;
			this._color = color;
			addEventListener( Event.ADDED_TO_STAGE, onAdded);
		}
		
		public function open(): void	{
			visible = true;
			TweenLite.killTweensOf(this);
			TweenLite.to(this, 0.3, { alpha:1 } );
		}
		
		public function close(): void	{
			TweenLite.killTweensOf(this);
			TweenLite.to(this, 0.3, { alpha:0, onComplete:closeComplete } );
			function closeComplete(): void	{
				visible = false;
			}
		}
		
		private function onAdded(e:Event):void 		{
			setLayout();
			addEvent();
			boxSet();
		}
		
		private function setLayout(): void	{
			box = new Sprite();
			box.graphics.beginFill(_color, _alpha);
			box.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
			box.graphics.endFill();
			addChild(box);
			this.visible = false;
			this.alpha = 0;
		}
		
		private function addEvent(): void	{
			stage.addEventListener(Event.RESIZE, onResize);
			function onResize( e: Event ): void	{
				boxSet();
			}
		}
		
		private function boxSet(): void	{
			box.x = (dcWidth - stage.stageWidth) / 2;
			box.y = (dcHeight - stage.stageHeight) / 2;
			box.width = stage.stageWidth;
			box.height = stage.stageHeight;
		}
	}
}